/*
 * @lc app=leetcode.cn id=1507 lang=typescript
 *
 * [1507] 转变日期格式
 */

// @lc code=start
function reformatDate(date: string): string {
    const Months = [
        "Jan",
        "Feb",
        "Mar",
        "Apr",
        "May",
        "Jun",
        "Jul",
        "Aug",
        "Sep",
        "Oct",
        "Nov",
        "Dec",
    ];
    const keepTwo = (s: number) => {
        let str = s.toString();
        return str.length === 1 ? "0" + str : str;
    };
    const [day, month, year] = date.split(" ");
    return (
        year +
        "-" +
        keepTwo(Months.indexOf(month) + 1) +
        "-" +
        keepTwo(parseInt(day))
    );
}
// @lc code=end
